home *** CD-ROM | disk | FTP | other *** search
/ Web Designer 98 (Professional) / WebDesigner 1.0.iso / tutorials / tutorial / rainbow.txt < prev    next >
Encoding:
Text File  |  1997-06-15  |  1.9 KB  |  55 lines

  1. <script language="JavaScript">
  2. <!-- Hide the script from old browsers --
  3.  
  4. // Michael P. Scholtis (mpscho@planetx.bloomu.edu)
  5. // All rights reserved.  January 15, 1996
  6. // You may use this JavaScript example as you see fit, as long as the
  7. // information within this comment above is included in your script.
  8.  
  9.  
  10. function MakeArray(n){
  11.    this.length=n;
  12.    for(var i=1; i<=n; i++) this[i]=i-1;
  13.    return this
  14. }
  15.  
  16. hex=new MakeArray(16);
  17. hex[11]="A"; hex[12]="B"; hex[13]="C"; hex[14]="D"; hex[15]="E"; hex[16]="F";
  18.  
  19. function ToHex(x){              // Changes a int to hex (in the range 0 to 255)
  20.    var high=x/16;
  21.    var s=high+"";               //1
  22.    s=s.substring(0,2);          //2 the combination of these are the same as the trunc function
  23.    high=parseInt(s,10);         //3
  24.    var left=hex[high+1];        // left part of the hex-value
  25.    var low=x-high*16;           // calculate the rest of the values
  26.    s=low+"";                    //1
  27.    s=s.substring(0,2);          //2 the combination of these are the same as the trunc function
  28.    low=parseInt(s,10);          //3
  29.    var right=hex[low+1];        // right part of the hex-value
  30.    var string=left+""+right;    // add the high and low together
  31.    return string;
  32. }
  33.  
  34. function rainbow(text){
  35.    text=text.substring(3,text.length-4);        // gets rid of the HTML-comment-tags
  36.    color_d1=255;                                // any value in 'begin' 0 to 255
  37.    mul=color_d1/text.length;
  38.    for(i=0;i < text.length;i++){
  39.       color_d1=255*Math.sin(i/(text.length/3)); // some other things you can try >> "=255-mul*i" to fade out, "=mul*i" to fade in, or try "255*Math.sin(i/(text.length/3))"
  40.       color_h1=ToHex(color_d1);
  41.       color_d2=mul*i;
  42.       color_h2=ToHex(color_d2);
  43.       document.write("<FONT COLOR='#FF"+color_h1+color_h2+"'>"+text.substring(i,i+1)+'</FONT>');
  44.    }
  45. }
  46.  
  47. // --End Hiding Here -->
  48. </script>
  49.  
  50. <SCRIPT>
  51. <!--
  52.    {rainbow("--> THIS IS WHERE YOUR TEXT GOES <!--");} 
  53. //-->
  54. </SCRIPT><br>
  55.